package ua.net.gm.server.world;

import ua.net.gm.server.primitives.Point;
import ua.net.gm.server.primitives.Size;

/**
 * Whole world in one object with map, persons, objects, etc
 *
 * @author syar
 */
public class World
{
    private final WorldId id;

    private final Size size;

    private final Field[][] area;

    public World(WorldId id, Size size)
    {
        if (id == null)
        {
            throw new IllegalArgumentException("World id can't be null");
        }
        this.id = id;
        if (size == null)
        {
            throw new IllegalArgumentException("World size can't be null");
        }
        this.size = size;
        this.area = new Field[size.getWidth()][size.getHeight()];
    }

    public Size getSize()
    {
        return size;
    }

    public WorldId getId()
    {
        return id;
    }

    public Field getField(int x, int y)
    {
        return area[x][y];
    }

    public Field getField(Point point)
    {
        return area[point.getX()][point.getY()];
    }

    public void setField(int x, int y, Field field)
    {
        area[x][y] = field;
    }

    public void setField(Point point, Field field)
    {
        area[point.getX()][point.getY()] = field;
    }
}
